package com.huaxiafinance.management.service.impl;

import com.huaxiafinance.management.mapper.UserSignRuleMapper;
import com.huaxiafinance.management.model.UserSignRule;
import com.huaxiafinance.management.service.UserSignRuleService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 签到规则管理的实现类
 * Created by hank on 2017/9/4.
 */
@Service("signRuleService")
public class UserSignRuleServiceImpl implements UserSignRuleService {

    private static final Logger logger = Logger.getLogger(UserSignRuleServiceImpl.class);

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    private UserSignRuleMapper userSignRuleMapper;




    /*   * 获取签到规则列表
     */
    @Override
    public List<UserSignRule> selectList() {
        return  userSignRuleMapper.selectList();
    }

    /**
     * 更改签到规则
     * @param records
     * @return
     */
    @Override
    @Transactional
    public boolean update(List<UserSignRule> records) {
        boolean flag = true ;
        try {
            for (UserSignRule rule:records){
                int n = userSignRuleMapper.updateByPrimaryKeySelective(rule);
                if(n<1){
                    flag = false;
                    break;
                }
            }
        }catch (Exception e){
            logger.error(e.getMessage(), e);
        }
        return flag;
    }
}
